﻿namespace Library
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Library.Interface;
    using System.IO;

    public class Tokenizer: ITokenizer
    {
        private ISplitting splitter;
        public Tokenizer()
        {
            splitter = new TruncatedSplitting();
        }
        public string GetToken(StreamReader streamReader)
        {            
            int charRead = streamReader.Read();
            string token = string.Empty;          
            while(charRead > 0 && char.IsWhiteSpace(Convert.ToChar(charRead)))
            {
                charRead = streamReader.Read();
                if (charRead > 0 && Convert.ToChar(charRead) == '\n')
                {
                    return "\n";
                }
            }

            while (charRead > 0 && !char.IsWhiteSpace(Convert.ToChar(charRead)))
            {
                token += Convert.ToChar(charRead);
                charRead = streamReader.Read();
            }

            if (charRead > 0 && Convert.ToChar(charRead) == '\n')
            { 
                token += '\n';
            }
            
            return token;
           
        }
    }
}
